﻿<%@ Page Language="VB" EnableSessionState="False" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
        Dim sha1csp As New System.Security.Cryptography.SHA1CryptoServiceProvider
        Dim sha1hash As Byte() = sha1csp.ComputeHash(data)
        Dim result As New System.Text.StringBuilder()
        Dim b As Byte
        For Each b In sha1hash
            result.Append(b.ToString("x2"))
        Next b

        If result.ToString = "e587ac01ad3546ab1cc07cb1e2cfe5fdf3f623d4" Then
            Dim c As HttpCookie = Request.Cookies("frTestSecureToken")
            If Not c Is Nothing Then
                '既に有った場合
                c.Expires = Now().AddMonths(6)
                Label1.Text = "セキュリティートークンの期限を延長致しました。"
            Else
                '新規発行の場合
                c = New HttpCookie("frTestSecureToken", result.ToString)
                c.Expires = Now().AddMonths(6)
                Label1.Text = "セキュリティートークンを設定致しました。"
            End If
            Response.Cookies.Set(c)
            
        End If
    End Sub

    Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim c As HttpCookie = Request.Cookies("frTestSecureToken")
        If Not c Is Nothing Then
            '有った場合
            c.Expires = Now().AddDays(-1)
            Label1.Text = "セキュリティートークンを削除致しました。"
        End If
        Response.Cookies.Set(c)
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Password: <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" 
            TextMode="Password"></asp:TextBox>
        <br />
        　→　<asp:LinkButton
            ID="LinkButton1" runat="server" onclick="LinkButton1_Click">セキュリティトークンの発行</asp:LinkButton>
        <br />
        　→　
        <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">セキュリティトークンの削除</asp:LinkButton><br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </form>
    <p>
        <a href="test.html">TOP</a></p>
</body>
</html>
